/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.turingtechnologies.materialscrollbardemo.slice;

import com.turingtechnologies.materialscrollbardemo.MaterialScrollBar;
import com.turingtechnologies.materialscrollbardemo.ResourceTable;
import com.turingtechnologies.materialscrollbardemo.adapters.IconProvider;
import com.turingtechnologies.materialscrollbardemo.bean.IconBean;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.*;

import java.util.ArrayList;
import java.util.List;

public class IconAbilitySlice extends AbilitySlice {
    private Text Id_id_fragment;
    private DependentLayout dl_icon;
    private int[] resLayout = new int[]{ ResourceTable.Layout_page_icon
    };

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_icon);
        Id_id_fragment = (Text) findComponentById(ResourceTable.Id_id_fragment);
        dl_icon = (DependentLayout) findComponentById(ResourceTable.Id_dl_icon);

        Id_id_fragment.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent mIntent = new Intent();
                Operation operation;
                operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.turingtechnologies.materialscrollbardemo")
                        .withAbilityName("com.turingtechnologies.materialscrollbardemo.MultiFragmentAbility")
                        .build();
                mIntent.setOperation(operation);
                startAbility(mIntent);
                component.getContext().setTransitionAnimation(0,0);
            }
        });


        MaterialScrollBar materiaScroller = (MaterialScrollBar) findComponentById(ResourceTable.Id_fast);
        ListContainer listContainer = (ListContainer) findComponentById(ResourceTable.Id_list_con);
        List<IconBean> list = getData();
        IconProvider itemPro = new IconProvider(list,this);
        listContainer.setItemProvider(itemPro);
        materiaScroller.setListContainer(listContainer, 2,0);
    }
    private ArrayList<IconBean> getData() {
        ArrayList<IconBean> data = new ArrayList<>();
            data.add(new IconBean("图库",ResourceTable.Media_two));
            data.add(new IconBean("设置",ResourceTable.Media_three));
            data.add(new IconBean("58",ResourceTable.Media_four));
            data.add(new IconBean("a",ResourceTable.Media_five));
            data.add(new IconBean("b",ResourceTable.Media_six));
            data.add(new IconBean("UC",ResourceTable.Media_seven));
            data.add(new IconBean("WPS",ResourceTable.Media_eight));
            data.add(new IconBean("主题",ResourceTable.Media_night));
            data.add(new IconBean("云空间",ResourceTable.Media_ten));
            data.add(new IconBean("京东",ResourceTable.Media_one));
            data.add(new IconBean("今日头条",ResourceTable.Media_seven));
        return data;
    }
    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
